<html>
<head>
<meta name="collection" content="exclude">

<title>The Java Language Specification
 LALR(1) Grammar </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
 
<table border="0" width="100%">
<tr>
<td><a href="index.html">Contents</a> | <a href="18.doc.html">Prev</a> | <a href="javalang.doc.html">Next</a> | <a href="j.index.doc1.html">Index</a></td>
<td align=right><i>Java Language Specification</i><br>
<font size="-1">First Edition</font></td></tr></table>
<hr><br>
 
<a name="52994"></a>
<p><strong>
CHAPTER
 19 </strong></p>
<a name="52996"></a>
<h1>LALR(1) Grammar </h1>
<hr><p>
<a name="26238"></a>
This chapter presents a grammar for Java. The grammar has been mechanically 
checked to insure that it is LALR(1).
<p><a name="26239"></a>
The grammar for Java presented piecemeal in the preceding chapters is much better for exposition, but it cannot be parsed left-to-right with one token of lookahead because of certain syntactic peculiarities, some of them inherited from C and C++. These problems and the solutions adopted for the LALR(1) grammar are presented below, followed by the grammar itself.<p>
<a name="44467"></a>
<h2>19.1    Grammatical Difficulties</h2>
<a name="44468"></a>
There are five problems with the grammar presented in preceding chapters.
<p><a name="44469"></a>
<h3>19.1.1    Problem #1: Names Too Specific</h3>
<a name="44470"></a>
Consider the two groups of productions:
<p><ul><pre>
<sub><i>PackageName:<br>
</i></sub>	<i>Identifier<br>
</i>	<i>PackageName</i><code> . </code><i>Identifier
</i>
<i>TypeName:<br>
</i>	<i>Identifier<br>
</i>	<i>PackageName</i><code> . </code><i>Identifier
</i></pre></ul><a name="44473"></a>
and:
<p><ul><pre>
<i>MethodName:<br>
</i>	<i>Identifier<br>
</i>	<i>AmbiguousName</i><code> . </code><i>Identifier
</i>
<i>AmbiguousName:<br>
</i>	<i>Identifier<br>
</i>	<i>AmbiguousName</i><code> . </code><i>Identifier
</i></pre></ul><a name="44476"></a>
Now consider the partial input:
<p><pre><a name="44477"></a>class Problem1 { int m() { hayden.
</pre><a name="44478"></a>
When the parser is considering the token <code>hayden</code>, with one-token lookahead to 
symbol "<code>.</code>", it cannot yet tell whether <code>hayden</code> should be a <i>PackageName</i> that 
qualifies a type name, as in:
<p><pre><a name="44479"></a>hayden.Dinosaur rex = new hayden.Dinosaur(2);
</pre><a name="44480"></a>
or an <i>AmbiguousName</i> that qualifies a method name, as in:
<p><pre><a name="44481"></a>hayden.print("Dinosaur Rex!");
</pre><a name="44482"></a>
Therefore, the productions shown above result in a grammar that is not LALR(1). 
There are also other problems with drawing distinctions among different kinds of 
names in the grammar.
<p><a name="44483"></a>
The solution is to eliminate the nonterminals <i>PackageName</i>, <i>TypeName</i>, <i>ExpressionName</i>, <i>MethodName</i>, and <i>AmbiguousName</i>, replacing them all with a single nonterminal <i>Name</i>:<p>
<ul><pre>
<i>Name:<br>
	SimpleName<br>
	QualifiedName
</i>
<i>SimpleName:<br>
	Identifier
</i>
<i>QualifiedName:<br>
	Name</i><code> . </code><i>Identifier
</i></pre></ul><a name="44487"></a>
A later stage of compiler analysis then sorts out the precise role of each name or 
name qualifier.
<p><a name="44578"></a>
For related reasons, these productions in <a href="4.doc.html#9317">&#167;4.3</a>:<p>
<ul><pre>
<i>ClassOrInterfaceType:<br>
</i>	<i>ClassType<br>
</i>	<i>InterfaceType
</i>
<i>ClassType:<br>
</i>	<i>TypeName
</i>
<i>InterfaceType:<br>
</i>	<i>TypeName
</i></pre></ul><a name="44679"></a>
were changed to:
<p><ul><pre>
<i>ClassOrInterfaceType:<br>
</i>	<i>Name
</i>
<i>ClassType:<br>
</i><code>	</code><i>ClassOrInterfaceType
</i>
<i>InterfaceType:<br>
</i><code>	</code><i>ClassOrInterfaceType
</i></pre></ul><a name="44488"></a>
<h3>19.1.2    Problem #2: Modifiers Too Specific</h3>
<a name="44489"></a>
Consider the two groups of productions:
<p><ul><pre>
<i>FieldDeclaration:<br>
	FieldModifiers</i><sub><i>opt</i></sub><code> </code><i>Type</i><code> </code><i>VariableDeclarators</i><code> ;
</code>
<i>FieldModifiers:<br>
</i>	<i>FieldModifier<br>
</i>	<i>FieldModifiers</i><code> </code><i>FieldModifier
</i>
<i>FieldModifier:</i> <i>one</i> <i>of<br>
</i>	<code>public</code>&#32;<code>protected</code>&#32;<code>private<br>
	final&#32;static&#32;transient&#32;volatile
</code></pre></ul><a name="44493"></a>
and:
<p><ul><pre>
<i>MethodHeader:<br>
</i>	<i>MethodModifiers</i><sub><i>opt</i></sub><code> </code><i>ResultType</i><code> </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt
</i></sub>
<i>MethodModifiers:<br>
</i>	<i>MethodModifier<br>
</i>	<i>MethodModifiers</i><code> </code><i>MethodModifier
</i>
<i>MethodModifier:</i> <i>one</i> <i>of<br>
</i>	<code>public</code>&#32;<code>protected</code>&#32;<code>private<br>
	static<br>
	abstract&#32;final&#32;native&#32;synchronized
</code></pre></ul><a name="44497"></a>
Now consider the partial input:
<p><pre><a name="44498"></a>class Problem2 { public static int
</pre><a name="44499"></a>
When the parser is considering the token <code>static</code>, with one-token lookahead to 
symbol <code>int</code>-or, worse yet, considering the token <code>public</code> with lookahead to 
<code>static</code>-it cannot yet tell whether this will be a field declaration such as:
<p><pre><a name="44500"></a>public static int maddie = 0;
</pre><a name="44501"></a>
or a method declaration such as:
<p><pre><a name="44502"></a>public static int maddie(String art) { return art.length(); }
</pre><a name="44503"></a>
Therefore, the parser cannot tell with only one-token lookahead whether <code>static</code> 
(or, similarly, <code>public</code>) should be reduced to <i>FieldModifier</i> or <i>MethodModifier</i>. 
Therefore, the productions shown above result in a grammar that is not LALR(1). 
There are also other problems with drawing distinctions among different kinds of 
modifiers in the grammar.
<p><a name="44504"></a>
While not all contexts provoke the problem, the simplest solution is to combine all contexts in which such modifiers are used, eliminating all six of the nonterminals &#32;<i>ClassModifiers </i><a href="8.doc.html#21613">(&#167;8.1.2)</a>, <i>FieldModifiers </i><a href="8.doc.html#78091">(&#167;8.3.1)</a>, <i>MethodModifiers </i><a href="8.doc.html#78188">(&#167;8.4.3)</a>, <i>ConstructorModifiers </i><a href="8.doc.html#42018">(&#167;8.6.3)</a>, <i>InterfaceModifiers </i><a href="9.doc.html#235947">(&#167;9.1.2)</a>, and <i>ConstantModifiers</i> &#32;<a href="9.doc.html#78642">(&#167;9.3)</a> from the grammar, replacing them all with a single nonterminal <i>Modifiers</i>:<p>
<ul><pre>
<i>Modifiers:<br>
	Modifier<br>
	Modifiers</i><code> </code><i>Modifier
</i>
<i>Modifier: one of<br>
	</i><code>public protected private<br>
	static<br>
	abstract final native synchronized transient volatile
</code></pre></ul><a name="44525"></a>
A later stage of compiler analysis then sorts out the precise role of each modifier 
and whether it is permitted in a given context.
<p><a name="44526"></a>
<h3>19.1.3    Problem #3: Field Declaration versus Method Declaration</h3>
<a name="44527"></a>
Consider the two productions (shown after problem #2 has been corrected):
<p><ul><pre>
<i>FieldDeclaration:<br>
	Modifiers</i><sub><i>opt</i></sub><code> </code><i>Type</i><code> </code><i>VariableDeclarators</i><code> ;
</code></pre></ul><a name="44529"></a>
and:
<p><ul><pre>
<i>MethodHeader:<br>
</i>	<i>Modifiers</i><sub><i>opt</i></sub><code> </code><i>ResultType</i><code> </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt
</i></sub></pre></ul><a name="44531"></a>
where <i>ResultType</i> is defined as:
<p><ul><pre>
<i>ResultType:<br>
</i>	<i>Type<br>
</i>	<code>void
</code></pre></ul><a name="44533"></a>
Now consider the partial input:
<p><pre><a name="44534"></a>class Problem3 { int julie
</pre><a name="44535"></a>
Note that, in this simple example, no <i>Modifiers</i> are present. When the parser is 
considering the token <code>int</code>, with one-token lookahead to symbol <code>julie</code>, it cannot 
yet tell whether this will be a field declaration such as:
<p><pre><a name="44536"></a>int julie = 14;
</pre><a name="44537"></a>
or a method declaration such as:
<p><pre><a name="44538"></a>int julie(String art) { return art.length(); }
</pre><a name="44539"></a>
Therefore, after the parser reduces <code>int</code> to the nonterminal <i>Type</i>, it cannot tell with 
only one-token lookahead whether <i>Type</i> should be further reduced to <i>ResultType</i> 
(for a method declaration) or left alone (for a field declaration). Therefore, the 
productions shown above result in a grammar that is not LALR(1).
<p><a name="44540"></a>
The solution is to eliminate the <i>ResultType</i> production and to have separate alternatives for <i>MethodHeader</i>:<p>
<ul><pre>
<i>MethodHeader:<br>
</i>	<i>Modifiers</i><sub><i>opt</i></sub><code> </code><i>Type</i><code> </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt<br>
</i></sub>	<i>Modifiers</i><sub><i>opt</i></sub><code> void </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt
</i></sub></pre></ul><a name="44542"></a>
This allows the parser to reduce <code>int</code> to <i>Type</i> and then leave it as is, delaying the decision as to whether a field declaration or method declaration is in progress.<p>
<a name="44543"></a>
<h3>19.1.4    Problem #4: Array Type versus Array Access</h3>
<a name="44544"></a>
Consider the productions (shown after problem #1 has been corrected):
<p><ul><pre>
<i>ArrayType:<br>
</i><code>	</code><i>Type</i><code> [ ]
</code></pre></ul><a name="44546"></a>
and:
<p><ul><pre>
<i>ArrayAccess:<br>
</i>	<i>Name</i><code> [ </code><i>Expression</i><code> ]<br>
</code>	<i>PrimaryNoNewArray</i><code> [ </code><i>Expression</i><code> ]
</code></pre></ul><a name="44548"></a>
Now consider the partial input:
<p><pre><a name="44549"></a>class Problem4 { Problem4() { peter[
</pre><a name="44550"></a>
When the parser is considering the token <code>peter</code>, with one-token lookahead to 
symbol <code>[</code>, it cannot yet tell whether <code>peter</code> will be part of a type name, as in:
<p><pre><a name="44551"></a>peter[] team;
</pre><a name="44552"></a>
or part of an array access, as in:
<p><pre><a name="44553"></a>peter[3] = 12;
</pre><a name="44554"></a>
Therefore, after the parser reduces <code>peter</code> to the nonterminal <i>Name</i>, it cannot tell 
with only one-token lookahead whether <i>Name</i> should be reduced ultimately to 
<i>Type</i> (for an array type) or left alone (for an array access). Therefore, the productions
shown above result in a grammar that is not LALR(1).
<p><a name="44555"></a>
The solution is to have separate alternatives for <em>ArrayType</em>:<p>
<ul><pre>
<i>ArrayType:<br>
</i><code>	</code><i>PrimitiveType</i><code> [ ]<br>
	</code><i>Name</i><code> [ ]<br>
	</code><i>ArrayType</i><code> [ ]
</code></pre></ul><a name="44557"></a>
This allows the parser to reduce <code>peter</code> to <i>Name</i> and then leave it as is, delaying 
the decision as to whether an array type or array access is in progress.
<p><a name="44559"></a>
<h3>19.1.5    Problem #5: Cast versus Parenthesized Expression</h3>
<a name="44560"></a>
Consider the production:
<p><ul><pre>
<i>CastExpression:<br>
</i><code>	( </code><i>PrimitiveType</i><code> ) </code><i>UnaryExpression<br>
</i><code>	( </code><i>ReferenceType</i><code> ) </code><i>UnaryExpressionNotPlusMinus
</i></pre></ul><a name="44562"></a>
Now consider the partial input:
<p><pre><a name="44563"></a>class Problem5 { Problem5() { super((matthew)
</pre><a name="44564"></a>
When the parser is considering the token <code>matthew</code>, with one-token lookahead to 
symbol <code>)</code>, it cannot yet tell whether <code>(matthew)</code> will be a parenthesized expression,
as in:
<p><pre><a name="44565"></a>super((matthew), 9);
</pre><a name="44566"></a>
or a cast, as in:
<p><pre><a name="44567"></a>super((matthew)baz, 9);
</pre><a name="44568"></a>
Therefore, after the parser reduces <code>matthew</code> to the nonterminal <i>Name</i>, it cannot 
tell with only one-token lookahead whether <i>Name</i> should be further reduced to 
<i>PostfixExpression</i> and ultimately to <i>Expression</i> (for a parenthesized expression) or 
to <i>ClassOrInterfaceType</i> and then to <i>ReferenceType</i> (for a cast). Therefore, the 
productions shown above result in a grammar that is not LALR(1).
<p><a name="44569"></a>
The solution is to eliminate the use of the nonterminal <i>ReferenceType</i> in the definition of <i>CastExpression</i>, which requires some reworking of both alternatives to avoid other ambiguities:<p>
<ul><pre>
<i>CastExpression:<br>
</i><code>	( </code><i>PrimitiveType</i><code> </code><i>Dims</i><sub><i>opt</i></sub><code> ) </code><i>UnaryExpression<br>
</i><code>	( </code><i>Expression</i><code> ) </code><i>UnaryExpressionNotPlusMinus<br>
	</i><code>( </code><i>Name</i><code> </code><i>Dims</i><code> ) </code><i>UnaryExpressionNotPlusMinus
</i></pre></ul><a name="44571"></a>
This allows the parser to reduce <code>matthew</code> to <i>Expression</i> and then leave it there, 
delaying the decision as to whether a parenthesized expression or a cast is in 
progress. Inappropriate variants such as:
<p><pre><a name="44572"></a>(int[])+3
</pre><a name="44573"></a>
and:
<p><pre><a name="44574"></a>(matthew+1)baz
</pre><a name="44575"></a>
must then be weeded out and rejected by a later stage of compiler analysis.
<p><a name="28201"></a>
The remaining sections of this chapter constitute a LALR(1) grammar for Java syntax, in which the five problems described above have been solved.<p>
<a name="50220"></a>
<h2>19.2    Productions from <a href="2.doc.html#140845">&#167;2.3: The Syntactic Grammar</a></h2>
<ul><pre>
<i>Goal:<br>
</i>	<i>CompilationUnit
</i></pre></ul><a name="26306"></a>
<h2>19.3    Productions from <a href="3.doc.html#48198">&#167;3</a><a href="3.doc.html#44591">: Lexical Structure</a></h2>
<ul><pre>
<i>Literal:<br>
</i>	<i>IntegerLiteral<br>
</i>	<i>FloatingPointLiteral<br>
</i>	<i>BooleanLiteral<br>
</i>	<i>CharacterLiteral<br>
</i>	<i>StringLiteral<br>
</i>	<i>NullLiteral
</i></pre></ul><a name="26315"></a>
<h2>19.4    Productions from <a href="4.doc.html#95843">&#167;4</a><a href="4.doc.html#95845">: Types, Values, and Variables</a></h2>
<ul><pre>
<i>Type:<br>
</i><code>	</code><i>PrimitiveType<br>
</i>	<i>ReferenceType
</i>
<i>PrimitiveType:<br>
	NumericType<br>
	</i><code>boolean
</code>
<i>NumericType:<br>
</i>	<i>IntegralType<br>
</i>	<i>FloatingPointType
</i>
<i>IntegralType:</i> <i>one</i> <i>of<br>
</i>	<code>byte short int long char
</code>
<i>FloatingPointType:</i> <i>one</i> <i>of<br>
</i><code>	float double
</code>
<i>ReferenceType:<br>
</i>	<i>ClassOrInterfaceType<br>
</i>	<i>ArrayType
</i>
<i>ClassOrInterfaceType</i>:<br>
	<i>Name
</i>
<i>ClassType:<br>
</i><code>	</code><i>ClassOrInterfaceType
</i>
<i>InterfaceType:<br>
</i><code>	</code><i>ClassOrInterfaceType
</i>
<i>ArrayType:<br>
</i><code>	</code><i>PrimitiveType</i><code> [ ]<br>
	</code><i>Name</i><code> [ ]<br>
	</code><i>ArrayType</i><code> [ ]
</code></pre></ul><a name="26342"></a>
<h2>19.5    Productions from <a href="6.doc.html#48086">&#167;6</a><a href="6.doc.html#44352">: Names</a></h2>
<ul><pre>
<i>Name:<br>
	SimpleName<br>
	QualifiedName
</i>
<i>SimpleName:<br>
	Identifier
</i>
<i>QualifiedName:<br>
	Name</i><code> . </code><i>Identifier
</i></pre></ul><a name="26355"></a>
<h2>19.6    Productions from <a href="7.doc.html#34412">&#167;7</a><a href="7.doc.html#60384">: Packages</a></h2>
<ul><pre>
<i>CompilationUnit:<br>
	PackageDeclaration</i><sub><i>opt</i></sub><code> </code><i>ImportDeclarations</i><sub><i>opt</i></sub><code> </code><i>TypeDeclarations</i><sub><i>opt
</i></sub>
<i>ImportDeclarations:<br>
</i>	<i>ImportDeclaration<br>
</i>	<i>ImportDeclarations</i><code> </code><i>ImportDeclaration
</i>
<i>TypeDeclarations:<br>
</i>	<i>TypeDeclaration<br>
</i>	<i>TypeDeclarations</i><code> </code><i>TypeDeclaration
</i>
<i>PackageDeclaration:<br>
	</i><code>package </code><i>Name</i><code> ;
</code>
<i>ImportDeclaration:<br>
</i>	<i>SingleTypeImportDeclaration<br>
</i>	<i>TypeImportOnDemandDeclaration
</i>
<i>SingleTypeImportDeclaration:<br>
</i><code>	import </code><i>Name</i><code> ;
</code>
<i>TypeImportOnDemandDeclaration:<br>
	</i><code>import </code><i>Name</i><code> . * ;
</code>
<i>TypeDeclaration:<br>
</i>	<i>ClassDeclaration<br>
</i>	<i>InterfaceDeclaration<br>
</i>	<code>;
</code></pre></ul><a name="26373"></a>
<h2>19.7    Productions Used Only in the LALR(1) Grammar</h2>
<ul><pre>
<i>Modifiers:<br>
	Modifier<br>
	Modifiers</i><code> </code><i>Modifier
</i>
<i>Modifier: one of<br>
	</i><code>public protected private<br>
	static<br>
	abstract final native synchronized transient volatile
</code></pre></ul><a name="26384"></a>
<h2>19.8    Productions from <a href="8.doc.html#3857">&#167;8</a><a href="8.doc.html#44365">: Classes</a></h2>
<a name="26388"></a>
<h3>19.8.1    Productions from <a href="8.doc.html#15372">&#167;8.1: Class Declaration</a></h3>
<ul><pre>
<i>ClassDeclaration:<br>
</i>	<i>Modifiers</i><sub><i>opt</i></sub><code> class </code><i>Identifier</i><code> </code><i>Super</i><sub><i>opt</i></sub><code> </code><i>Interfaces</i><sub><i>opt</i></sub><code> </code><i>ClassBody
</i>
<i>Super:<br>
</i>	<code>extends </code><i>ClassType
</i>
<i>Interfaces:<br>
</i>	<code>implements </code><i>InterfaceTypeList
</i>
<i>InterfaceTypeList:<br>
</i>	<i>InterfaceType<br>
</i>	<i>InterfaceTypeList</i><code> , </code><i>InterfaceType
</i>
<i>ClassBody:<br>
	</i><code>{ </code><i>ClassBodyDeclarations</i><sub><i>opt</i></sub><code> }
</code>
<i>ClassBodyDeclarations:<br>
</i>	<i>ClassBodyDeclaration<br>
</i>	<i>ClassBodyDeclarations</i><code> </code><i>ClassBodyDeclaration
</i>
<i>ClassBodyDeclaration:<br>
	ClassMemberDeclaration<br>
	StaticInitializer<br>
	ConstructorDeclaration
</i>
<i>ClassMemberDeclaration:<br>
	FieldDeclaration<br>
</i>	<i>MethodDeclaration
</i></pre></ul><a name="26408"></a>
<h3>19.8.2    Productions from <a href="8.doc.html#40898">&#167;8.3: Field Declarations</a></h3>
<ul><pre>
<i>FieldDeclaration:<br>
	Modifiers</i><sub><i>opt</i></sub><code> </code><i>Type</i><code> </code><i>VariableDeclarators</i><code> ;
</code>
<i>VariableDeclarators:<br>
</i>	<i>VariableDeclarator<br>
</i>	<i>VariableDeclarators</i><code> , </code><i>VariableDeclarator
</i>
<i>VariableDeclarator:<br>
</i>	<i>VariableDeclaratorId<br>
</i>	<i>VariableDeclaratorId</i><code> = </code><i>VariableInitializer
</i>
<i>VariableDeclaratorId:<br>
</i>	<i>Identifier<br>
</i>	<i>VariableDeclaratorId</i><code> [ ]
</code>
<i>VariableInitializer:<br>
</i>	<i>Expression<br>
</i>	<i>ArrayInitializer
</i></pre></ul><a name="26422"></a>
<h3>19.8.3    Productions from <a href="8.doc.html#40420">&#167;8.4: Method Declarations</a></h3>
<ul><pre>
<i>MethodDeclaration:<br>
</i>	<i>MethodHeader</i><code> </code><i>MethodBody
</i>
<i>MethodHeader:<br>
</i>	<i>Modifiers</i><sub><i>opt</i></sub><code> </code><i>Type</i><code> </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt<br>
</i></sub>	<i>Modifiers</i><sub><i>opt</i></sub><code> void </code><i>MethodDeclarator</i><code> </code><i>Throws</i><sub><i>opt
</i></sub>
<i>MethodDeclarator:<br>
</i>	<i>Identifier</i><code> ( </code><i>FormalParameterList</i><sub><i>opt</i></sub><code> )<br>
</code>	<i>MethodDeclarator</i><code> [ ]
</code>
<i>FormalParameterList:<br>
</i>	<i>FormalParameter<br>
</i>	<i>FormalParameterList</i><code> , </code><i>FormalParameter
</i>
<i>FormalParameter:<br>
</i>	<i>Type</i><code> </code><i>VariableDeclaratorId
</i>
<i>Throws:<br>
</i><code>	throws </code><i>ClassTypeList
</i>
<i>ClassTypeList:<br>
</i>	<i>ClassType<br>
</i>	<i>ClassTypeList</i><code> , </code><i>ClassType
</i>
<i>MethodBody:<br>
	Block</i> <br>
	<code>;
</code></pre></ul><a name="26442"></a>
<h3>19.8.4    Productions from <a href="8.doc.html#39245">&#167;8.5: Static Initializers</a></h3>
<ul><pre>
<i>StaticInitializer:<br>
</i>	<code>static </code><i>Block
</i></pre></ul><a name="44248"></a>
<h3>19.8.5    Productions from <a href="8.doc.html#41652">&#167;8.6: Constructor Declarations</a></h3>
<ul><pre>
<i>ConstructorDeclaration:<br>
	Modifiers</i><sub><i>opt</i></sub><code> </code><i>ConstructorDeclarator</i><code> </code><i>Throws</i>opt<code> </code><i>ConstructorBody
</i>
<i>ConstructorDeclarator:<br>
</i><code>	</code><i>SimpleName</i><code> ( </code><i>FormalParameterList</i><sub><i>opt</i></sub><code> )
</code>
<i>ConstructorBody:<br>
</i>	<code>{ </code><i>ExplicitConstructorInvocation</i><sub><i>opt</i></sub><code> </code><i>BlockStatements</i><sub><i>opt</i></sub><code> }
</code>
<i>ExplicitConstructorInvocation:<br>
</i>	<code>this ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> ) ;<br>
</code>	<code>super ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> ) ;
</code></pre></ul><a name="26463"></a>
<h2>19.9    Productions from <a href="9.doc.html#238678">&#167;9</a><a href="9.doc.html#238680">: Interfaces</a></h2>
<a name="26467"></a>
<h3>19.9.1    Productions from <a href="9.doc.html#35470">&#167;9.1: Interface Declarations</a></h3>
<ul><pre>
<i>InterfaceDeclaration:<br>
</i>	<i>Modifiers</i><sub><i>opt</i></sub><code> interface </code><i>Identifier</i><code> </code><i>ExtendsInterfaces</i><sub><i>opt</i></sub><code> </code><i>InterfaceBody
</i>
<i>ExtendsInterfaces:<br>
</i>	<code>extends </code><i>InterfaceType<br>
</i>	<i>ExtendsInterfaces</i><code> , </code><i>InterfaceType
</i>
<i>InterfaceBody</i>:<br>
<code>	{ </code><i>InterfaceMemberDeclarations</i><sub><i>opt</i></sub><code> }
</code>
<i>InterfaceMemberDeclarations:<br>
</i>	<i>InterfaceMemberDeclaration<br>
</i>	<i>InterfaceMemberDeclarations</i><code> </code><i>InterfaceMemberDeclaration
</i>
<i>InterfaceMemberDeclaration:<br>
</i>	<i>ConstantDeclaration<br>
</i>	<i>AbstractMethodDeclaration
</i>
<i>ConstantDeclaration:<br>
</i>	<i>FieldDeclaration
</i>
<i>AbstractMethodDeclaration:<br>
</i>	<i>MethodHeader</i><code> ;
</code></pre></ul><a name="26488"></a>
<h2>19.10    Productions from <a href="10.doc.html#27803">&#167;10</a><a href="10.doc.html#27805">: Arrays</a></h2>
<ul><pre>
<i>ArrayInitializer:<br>
</i>	<code>{ </code><i>VariableInitializers</i><sub><i>opt</i></sub><code> ,</code><sub><i>opt</i></sub><code> }
</code>
<i>VariableInitializers:<br>
</i>	<i>VariableInitializer<br>
</i>	<i>VariableInitializers</i><code> , </code><i>VariableInitializer
</i></pre></ul><a name="26499"></a>
<h2>19.11    Productions from <a href="14.doc.html#44383">&#167;14</a><a href="14.doc.html#101241">: Blocks and Statements</a></h2>
<ul><pre>
<i>Block:<br>
</i>	<code>{ </code><i>BlockStatements</i><sub><i>opt</i></sub><code> }
</code>
<i>BlockStatements:<br>
</i><code>	</code><i>BlockStatement<br>
</i><code>	</code><i>BlockStatements</i><code> </code><i>BlockStatement
</i>
<i>BlockStatement:<br>
</i>	<i>LocalVariableDeclarationStatement<br>
</i>	<i>Statement
</i>
<i>LocalVariableDeclarationStatement:<br>
</i>	<i>LocalVariableDeclaration</i><code> ;
</code>
<i>LocalVariableDeclaration:<br>
</i>	<i>Type</i><code> </code><i>VariableDeclarators
</i>
<i>Statement:<br>
</i>	<i>StatementWithoutTrailingSubstatement<br>
</i>	<i>LabeledStatement<br>
</i>	<i>IfThenStatement<br>
</i>	<i>IfThenElseStatement<br>
</i>	<i>WhileStatement<br>
</i>	<i>ForStatement
</i>
<i>StatementNoShortIf:<br>
</i>	<i>StatementWithoutTrailingSubstatement<br>
</i>	<i>LabeledStatementNoShortIf<br>
</i>	<i>IfThenElseStatementNoShortIf<br>
</i>	<i>WhileStatementNoShortIf<br>
</i>	<i>ForStatementNoShortIf
</i>
<i>StatementWithoutTrailingSubstatement:<br>
	Block<br>
	EmptyStatement<br>
	ExpressionStatement<br>
	SwitchStatement<br>
	DoStatement<br>
	BreakStatement<br>
	ContinueStatement<br>
	ReturnStatement<br>
	SynchronizedStatement<br>
	ThrowStatement<br>
	TryStatement
</i>
<i>EmptyStatement:<br>
</i>	<code>;
</code>
<i>LabeledStatement:<br>
</i>	<i>Identifier</i><code> : </code><i>Statement
</i>
<i>LabeledStatementNoShortIf:<br>
</i>	<i>Identifier</i><code> : </code><i>StatementNoShortIf
</i>
<i>ExpressionStatement:<br>
</i>	<i>StatementExpression</i><code> ;
</code>
<i>StatementExpression:<br>
</i>	<i>Assignment<br>
	PreIncrementExpression<br>
	PreDecrementExpression<br>
	PostIncrementExpression<br>
	PostDecrementExpression<br>
	MethodInvocation<br>
</i>	<i>ClassInstanceCreationExpression
</i></pre></ul><ul><pre>
<i>IfThenStatement:<br>
</i>	<code>if ( </code><i>Expression</i><code> ) </code><i>Statement
</i>
<i>IfThenElseStatement:<br>
</i>	<code>if ( </code><i>Expression</i><code> ) </code><i>StatementNoShortIf</i><code> else </code><i>Statement
</i>
<i>IfThenElseStatementNoShortIf:<br>
</i>	<code>if ( </code><i>Expression</i><code> ) </code><i>StatementNoShortIf</i><code> else </code><i>StatementNoShortIf
</i>
<i>SwitchStatement:<br>
</i><code>	switch ( </code><i>Expression</i><code> ) </code><i>SwitchBlock
</i>
<i>SwitchBlock:<br>
</i>	<code>{ </code><i>SwitchBlockStatementGroups</i><sub><i>opt</i></sub><code> </code><i>SwitchLabels</i><sub><i>opt</i></sub><code> }
</code>
<i>SwitchBlockStatementGroups:<br>
</i><code>	</code><i>SwitchBlockStatementGroup<br>
</i><code>	</code><i>SwitchBlockStatementGroups</i><code> </code><i>SwitchBlockStatementGroup
</i>
<i>SwitchBlockStatementGroup:<br>
</i>	<i>SwitchLabels</i><code> </code><i>BlockStatements
</i>
<i>SwitchLabels:<br>
</i>	<i>SwitchLabel<br>
</i>	<i>SwitchLabels</i><code> </code><i>SwitchLabel
</i>
<i>SwitchLabel:<br>
</i><code>	case </code><i>ConstantExpression</i><code> :<br>
	default :
</code>
<i>WhileStatement:<br>
</i>	<code>while ( </code><i>Expression</i><code> ) </code><i>Statement
</i>
<i>WhileStatementNoShortIf:<br>
</i>	<code>while ( </code><i>Expression</i><code> ) </code><i>StatementNoShortIf
</i>
<i>DoStatement:<br>
</i><code>	do </code><i>Statement</i><code> while ( </code><i>Expression</i><code> ) ;
</code></pre></ul><ul><pre>
<i>ForStatement:<br>
</i>	<code>for ( </code><i>ForInit</i><sub><i>opt</i></sub><code> ; </code><i>Expression</i><sub><i>opt</i></sub><code> ; </code><i>ForUpdate</i><sub><i>opt</i></sub><code> )<br>
</code>		<i>Statement
</i>
<i>ForStatementNoShortIf:<br>
</i>	<code>for ( </code><i>ForInit</i><sub><i>opt</i></sub><code> ; </code><i>Expression</i><sub><i>opt</i></sub><code> ; </code><i>ForUpdate</i><sub><i>opt</i></sub><code> )<br>
		</code><i>StatementNoShortIf
</i>
<i>ForInit:<br>
</i><code>	</code><i>StatementExpressionList<br>
</i>	<i>LocalVariableDeclaration
</i>
<i>ForUpdate:<br>
</i>	<i>StatementExpressionList
</i>
<i>StatementExpressionList:<br>
</i>	<i>StatementExpression<br>
</i>	<i>StatementExpressionList</i><code> , </code><i>StatementExpression
</i>
<i>BreakStatement:<br>
</i>	<code>break </code><i>Identifier</i><sub><i>opt</i></sub><code> ;
</code>
<i>ContinueStatement:<br>
</i>	<code>continu</code><i>e </i><i>Identifier</i><sub><i>opt</i></sub><code> ;
</code>
<i>ReturnStatement:<br>
</i>	<code>return </code><i>Expression</i><sub><i>opt</i></sub><code> ;
</code>
<i>ThrowStatement:<br>
</i>	<code>throw </code><i>Expression</i><code> ;
</code>
<i>SynchronizedStatement:<br>
</i>	<code>synchronized ( </code><i>Expression</i><code> ) </code><i>Block
</i>
<i>TryStatement:<br>
</i><code>	try </code><i>Block</i><code> </code><i>Catches<br>
	</i><code>try </code><i>Block</i><code> </code><i>Catches</i><sub><i>opt</i></sub><code> </code><i>Finally
</i>
<i>Catches:<br>
</i>	<i>CatchClause<br>
</i>	<i>Catches</i><code> </code><i>CatchClause
</i>
<i>CatchClause:<br>
</i>	<code>catch ( </code><i>FormalParameter</i><code> ) </code><i>Block
</i>
<i>Finally:<br>
</i><code>	finally </code><i>Block
</i></pre></ul><a name="26586"></a>
<h2>19.12    Productions from <a href="15.doc.html#4709">&#167;15</a><a href="15.doc.html#44393">: Expressions</a></h2>
<ul><pre>
<i>Primary:<br>
</i>	<i>PrimaryNoNewArray<br>
</i>	<i>ArrayCreationExpression
</i>
<i>PrimaryNoNewArray:<br>
</i>	<i>Literal<br>
</i><code>	this<br>
</code>	<code>( </code><i>Expression</i><code> )<br>
</code>	<i>ClassInstanceCreationExpression<br>
</i>	<i>FieldAccess<br>
</i>	<i>MethodInvocation<br>
</i>	<i>ArrayAccess
</i>
<i>ClassInstanceCreationExpression:<br>
</i>	<code>new </code><i>ClassType</i><code> ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> )
</code>
<i>ArgumentList:<br>
</i>	<i>Expression<br>
</i>	<i>ArgumentList</i><code> , </code><i>Expression
</i>
<i>ArrayCreationExpression:<br>
</i><sub><i>	</i></sub><code>new </code><i>PrimitiveType</i><code> </code><i>DimExprs</i><code> </code><i>Dims</i><sub><i>opt<br>
</i></sub>	<code>new </code><i>ClassOrInterfaceType</i><code> </code><i>DimExprs</i><code> </code><i>Dims</i><sub><i>opt
</i></sub>
<i>DimExprs:<br>
</i>	<i>DimExpr<br>
</i>	<i>DimExprs</i><code> </code><i>DimExpr
</i>
<i>DimExpr:<br>
</i>	<code>[ </code><i>Expression</i><code> ]
</code>
<i>Dims:<br>
</i>	<code>[ ]<br>
</code>	<i>Dims</i><code> [ ]
</code>
<i>FieldAccess:<br>
</i>	<i>Primary</i><code> . </code><i>Identifier<br>
</i>	<code>super . </code><i>Identifier
</i>
<i>MethodInvocation:<br>
</i>	<i>Name</i><code> ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> )<br>
</code>	<i>Primary</i><code> . </code><i>Identifier</i><code> ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> )<br>
	super . </code><i>Identifier</i><code> ( </code><i>ArgumentList</i><sub><i>opt</i></sub><code> )
</code>
<i>ArrayAccess:<br>
</i>	<i>Name</i><code> [ </code><i>Expression</i><code> ]<br>
</code>	<i>PrimaryNoNewArray</i><code> [ </code><i>Expression</i><code> ]
</code>
<i>PostfixExpression:<br>
	Primary<br>
	Name<br>
</i>	<i>PostIncrementExpression<br>
	PostDecrementExpression
</i>
<i>PostIncrementExpression:<br>
</i>	<i>PostfixExpression</i><code> ++
</code>
<i>PostDecrementExpression:<br>
</i>	<i>PostfixExpression</i><code> --
</code>
<i>UnaryExpression</i>:<br>
<code>	</code><i>PreIncrementExpression<br>
</i><code>	</code><i>PreDecrementExpression<br>
</i><code>	+ </code><i>UnaryExpression<br>
</i>	<code>- </code><i>UnaryExpression<br>
</i>	<i>UnaryExpressionNotPlusMinus
</i>
<i>PreIncrementExpression:<br>
</i><code>	++ </code><i>UnaryExpression
</i>
<i>PreDecrementExpression:<br>
</i>	<code>-- </code><i>UnaryExpression
</i>
<i>UnaryExpressionNotPlusMinus</i>:<br>
<code>	</code><i>PostfixExpression<br>
</i><code>	~ </code><i>UnaryExpression<br>
</i>	<code>! </code><i>UnaryExpression<br>
</i><code>	</code><i>CastExpression
</i>
<i>CastExpression:<br>
</i><code>	( </code><i>PrimitiveType</i><code> </code><i>Dims</i><sub><i>opt</i></sub><code> ) </code><i>UnaryExpression<br>
</i><code>	( </code><i>Expression</i><code> ) </code><i>UnaryExpressionNotPlusMinus<br>
	</i><code>( </code><i>Name</i><code> </code><i>Dims</i><code> ) </code><i>UnaryExpressionNotPlusMinus
</i>
<i>MultiplicativeExpression</i>:<br>
	<i>UnaryExpression<br>
</i>	<i>MultiplicativeExpression</i><code> * </code><i>UnaryExpression<br>
</i>	<i>MultiplicativeExpression</i><code> / </code><i>UnaryExpression<br>
</i>	<i>MultiplicativeExpression</i><code> % </code><i>UnaryExpression
</i>
<i>AdditiveExpression:<br>
</i>	<i>MultiplicativeExpression<br>
</i>	<i>AdditiveExpression</i><code> + </code><i>MultiplicativeExpression<br>
</i><code>	</code><i>AdditiveExpression</i><code> - </code><i>MultiplicativeExpression
</i>
<i>ShiftExpression:<br>
</i>	<i>AdditiveExpression<br>
</i>	<i>ShiftExpression</i><code> &lt;&lt; </code><i>AdditiveExpression<br>
</i>	<i>ShiftExpression</i><code> &gt;&gt; </code><i>AdditiveExpression<br>
</i>	<i>ShiftExpression</i><code> &gt;&gt;&gt; </code><i>AdditiveExpression
</i>
<i>RelationalExpression:<br>
</i>	<i>ShiftExpression<br>
</i>	<i>RelationalExpression</i><code> &lt; </code><i>ShiftExpression<br>
</i>	<i>RelationalExpression</i><code> &gt; </code><i>ShiftExpression<br>
</i>	<i>RelationalExpression</i><code> &lt;= </code><i>ShiftExpression<br>
</i>	<i>RelationalExpression</i><code> &gt;= </code><i>ShiftExpression<br>
</i>	<i>RelationalExpression</i><code> instanceof </code><i>ReferenceType
</i>
<i>EqualityExpression:<br>
</i>	<i>RelationalExpression<br>
</i>	<i>EqualityExpression</i><code> == </code><i>RelationalExpression<br>
</i>	<i>EqualityExpression</i><code> != </code><i>RelationalExpression
</i>
<i>AndExpression:<br>
</i>	<i>EqualityExpression<br>
</i>	<i>AndExpression</i><code> &amp; </code><i>EqualityExpression
</i>
<i>ExclusiveOrExpression:<br>
</i>	<i>AndExpression<br>
</i>	<i>ExclusiveOrExpression</i><code> ^ </code><i>AndExpression
</i>
<i>InclusiveOrExpression:<br>
</i>	<i>ExclusiveOrExpression<br>
</i>	<i>InclusiveOrExpression</i><code> | </code><i>ExclusiveOrExpression
</i>
<i>ConditionalAndExpression:<br>
</i>	<i>InclusiveOrExpression<br>
</i>	<i>ConditionalAndExpression</i><code> &amp;&amp; </code><i>InclusiveOrExpression
</i>
<i>ConditionalOrExpression:<br>
</i>	<i>ConditionalAndExpression<br>
</i>	<i>ConditionalOrExpression</i><code> || </code><i>ConditionalAndExpression
</i>
<i>ConditionalExpression:<br>
</i>	<i>ConditionalOrExpression<br>
</i>	<i>ConditionalOrExpression</i><code> ? </code>Expression<code> : </code><i>ConditionalExpression
</i>
<i>AssignmentExpression:<br>
</i>	<i>ConditionalExpression<br>
</i>	<i>Assignment
</i>
<i>Assignment:<br>
</i>	<i>LeftHandSide</i><code> </code><i>AssignmentOperator</i><code> </code><i>AssignmentExpression
</i>
<i>LeftHandSide:<br>
</i>	<i>Name<br>
</i>	<i>FieldAccess<br>
</i>	<i>ArrayAccess
</i>
<i>AssignmentOperator:</i> <i>one</i> <i>of<br>
</i>	<code>=&#32;*=&#32;/=&#32;%=&#32;+=&#32;-=&#32;&lt;&lt;=&#32;&gt;&gt;=&#32;&gt;&gt;&gt;=&#32;&amp;=&#32;^=&#32;|=
</code>
<i>Expression:<br>
</i>	<i>AssignmentExpression
</i>
<i>ConstantExpression:<br>
</i>	<i>Expression
</i></pre></ul><a name="47489"></a>
<p>


<hr>
<!-- This inserts footnotes-->
<table border="0" width="100%">
<tr>
<td><a href="index.html">Contents</a> | <a href="18.doc.html">Prev</a> | <a href="javalang.doc.html">Next</a> | <a href="j.index.doc1.html">Index</a></td>
<td align=right><i>Java Language Specification</i><br>
<font size="-1">First Edition</font></td></tr></table>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on April 03, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright &#169 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections via our <a href="http://developers.sun.com/contact/feedback.jsp?&category=doc&mailsubject=Java%20Language%20Specification%20Feedback">feedback form</a>
</font>
<script language="JavaScript" src="/js/omi/jsc/s_code_remote.js"></script></body></html>